#include <REGX52.H>
#include "LCD1602.h"
#include "delay.h"
#include "MatrixKey.h"

unsigned char KeyNum;
unsigned int pw;
const unsigned int password=1234;

void main(){
	bg:;
	LCD_init();
	LCD_ShowString(1,1,"Password:");
	for(;;){
		KeyNum=MatrixKey();
		if(KeyNum){
			if(KeyNum<=10){
				pw*=10;
				pw+=KeyNum%10;
			}else switch(KeyNum){
				case 11:
					LCD_init();
					if(pw==password){
						LCD_ShowString(1,1,"Welcome!");
						goto ed;
					}
					else{
						LCD_ShowString(1,1,"Wrong Password!");
						Delay(5000);
						goto bg;
					}break;
				case 12:
					pw/=10;
			}LCD_ShowNum(2,1,pw,4);
		}
	}while(1) ed:;
}
